package com.elitel.frame.base.controller;

import com.elitel.frame.base.service.CfgFileParamService;
import com.elitel.frame.main.entity.vo.CfgFileParamVo;
import com.elitel.frame.main.entity.vo.JsonResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author mulis
 */
@RequestMapping("cfgFileParam")
@RestController
public class CfgFileParamController {


    @Resource
    private CfgFileParamService fileParamService;


    @PostMapping("saveFileInfo")
    public JsonResult saveFileInfo(@RequestBody CfgFileParamVo param) {
        JsonResult jsonResult = new JsonResult();
        try {
            CfgFileParamVo cfgFileParamVo = fileParamService.saveFileInfo(param);
            jsonResult.setData(cfgFileParamVo);
            jsonResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setSuccess(false);
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }


    @PostMapping("getAttrList")
    public JsonResult getAttrList(@RequestBody CfgFileParamVo param) {
        JsonResult jsonResult = new JsonResult();
        try {
            List<CfgFileParamVo.Attr> attrList = fileParamService.getAttrList(param);
            jsonResult.setData(attrList);
            jsonResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setSuccess(false);
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }

    @PostMapping("getCfgInfo")
    public JsonResult getCfgInfo(@RequestBody Map<String, Object> map) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setSuccess(true);
        try {
            Object guid = map.get("guid");
            CfgFileParamVo res = fileParamService.getCfgInfo(guid + "");
            jsonResult.setData(res);
            jsonResult.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setSuccess(false);
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }


}
